# app/models/channel_permission.py
from app import db

class ChannelPermission(db.Model):
    __tablename__ = 'channel_permissions'

    permission_id = db.Column(db.String(36), primary_key=True)
    channel_id = db.Column(db.String(36), db.ForeignKey('channels.channel_id'), nullable=False)
    member_id = db.Column(db.String(36), db.ForeignKey('server_members.membership_id'), nullable=False)
    can_view = db.Column(db.Boolean, default=True)
    can_send = db.Column(db.Boolean, default=True)
    can_manage = db.Column(db.Boolean, default=False)
    can_connect = db.Column(db.Boolean, default=True)
    is_muted = db.Column(db.Boolean, default=False)

    channel = db.relationship('Channel', back_populates='permissions')
    member = db.relationship('ServerMember', back_populates='channel_permissions')

    def __repr__(self):
        return f'<ChannelPermission {self.permission_id} for member {self.member_id}>'